package com.juyu.miliao.api.service;

import com.alibaba.fastjson.JSONObject;
import com.juyu.miliao.api.domain.Appkey;
import com.juyu.miliao.api.domain.PicCheck;
import com.juyu.miliao.api.rabbitMQ.PicCheckRabbitMQ;
import com.juyu.miliao.common.constant.EnumAppKeyType;
import com.juyu.miliao.common.exception.ConsumeRuntimeException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PicCheckService {
    @Resource
    private PicCheckRabbitMQ picCheckRabbitMQ;

    @Resource
    private AppKeyService appKeyService;

    /**
     * 通过mq在定时器项目处理数据入库
     * @param picCheck
     */
    public void addPicCheck(PicCheck picCheck) {
        Appkey appKey = appKeyService.getAppKeyByKey(EnumAppKeyType.PIC_CHECK_PARAMETER.key);
        if(appKey == null){
            throw new ConsumeRuntimeException(EnumAppKeyType.PIC_CHECK_PARAMETER.key+"为空");
        }else{
            JSONObject jsStr = JSONObject.parseObject(appKey.getValue());
            int picCheckSwitch = Integer.parseInt(jsStr.get("picCheckSwitch").toString());
            if(picCheckSwitch !=1){
                throw new ConsumeRuntimeException("picCheckSwitch="+picCheckSwitch);
            }
        }

        picCheckRabbitMQ.timeDelaySavePicCheck(picCheck);
    }
}
